﻿<UserControl x:Class="FacebookClient.UpdateStatusControlModern" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:FacebookClient="clr-namespace:FacebookClient" xmlns:ClientManager="clr-namespace:ClientManager" xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls">
  <UserControl.Template>
    <ControlTemplate TargetType="{x:Type FacebookClient:UpdateStatusControlModern}">
      <ControlTemplate.Resources>
        <FacebookClient:IsStringNullOrWhitespaceConverter x:Key="IsStringNullOrWhitespaceConverter" />

        <Style x:Key="SmallIconButton" TargetType="{x:Type ButtonBase}">
          <Setter Property="FocusVisualStyle" Value="{x:Null}" />
          <Setter Property="SnapsToDevicePixels" Value="true" />
          <Setter Property="OverridesDefaultStyle" Value="true" />
          <Setter Property="FontFamily" Value="{DynamicResource SansSerifFont}" />
          <Setter Property="FontSize" Value="13" />
          <Setter Property="FontWeight" Value="Bold" />
          <Setter Property="Padding" Value="0" />
          <Setter Property="Cursor" Value="Hand" />
          <Setter Property="Height" Value="Auto" />
          <Setter Property="MinHeight" Value="0" />
          <Setter Property="Foreground" Value="White" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type ButtonBase}">
                <Grid Background="Transparent">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
                  <Path x:Name="Icon" MaxWidth="16" MaxHeight="14" Margin="{TemplateBinding Padding}" Data="{TemplateBinding Tag}" Fill="#FFFFFF" Stretch="Uniform" Opacity="0.5" />
                  <ContentPresenter Margin="4,0,0,0" Grid.Column="1" VerticalAlignment="Center" />
                </Grid>
                <ControlTemplate.Triggers>
                  <Trigger Property="IsMouseOver" Value="True">
                    <Trigger.EnterActions>
                      <BeginStoryboard>
                        <Storyboard>
                          <DoubleAnimation Storyboard.TargetName="Icon" Storyboard.TargetProperty="Opacity" To="1.0" Duration="00:00:00.1" />
                        </Storyboard>
                      </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                      <BeginStoryboard>
                        <Storyboard>
                          <DoubleAnimation Storyboard.TargetName="Icon" Storyboard.TargetProperty="Opacity" Duration="00:00:00.2" />
                        </Storyboard>
                      </BeginStoryboard>
                    </Trigger.ExitActions>
                  </Trigger>
                  <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" Value="0.5" />
                  </Trigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>

        <Style x:Key="SimpleCommandTextBox" TargetType="FacebookClient:CommandTextBox">
          <Setter Property="SnapsToDevicePixels" Value="True" />
          <Setter Property="FocusVisualStyle" Value="{x:Null}" />
          <Setter Property="OverridesDefaultStyle" Value="True" />
          <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
          <Setter Property="Padding" Value="3" />
          <Setter Property="FontFamily" Value="{DynamicResource SansSerifFont}" />
          <Setter Property="AllowDrop" Value="true" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="FacebookClient:CommandTextBox">
                <Border Background="White" CornerRadius="2">
                  <Grid Background="Transparent" Margin="{TemplateBinding Padding}">
                    <TextBlock x:Name="HelpText" Text="{TemplateBinding BannerText}" IsHitTestVisible="False" Opacity="0.5" Visibility="Collapsed" />
                    <ScrollViewer Margin="0" x:Name="PART_ContentHost" />
                  </Grid>
                </Border>
                <ControlTemplate.Triggers>
                  <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" Value="0.5" />
                  </Trigger>
                  <MultiTrigger>
                    <MultiTrigger.Conditions>
                      <Condition Property="IsFocused" Value="False" />
                      <Condition Property="Text" Value="" />
                    </MultiTrigger.Conditions>
                    <Setter TargetName="HelpText" Property="Visibility" Value="Visible" />
                  </MultiTrigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>

      </ControlTemplate.Resources>

      <Grid SnapsToDevicePixels="True" Width="{Binding ElementName=StatusPopupToggle, Path=ActualWidth}" Margin="10" Visibility="Visible">
        <Grid.Effect>
          <DropShadowEffect ShadowDepth="2" Direction="-90" BlurRadius="8" Opacity="0.5" />
        </Grid.Effect>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Path Data="M0,1 L0.5,0 L1,1 Z" Stretch="Fill" Width="23" Height="19" Fill="{DynamicResource ModernPopupTopBrush}" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="20,0,0,0" />
        <Border CornerRadius="4" Grid.Row="1" Grid.RowSpan="3" Grid.ColumnSpan="2" Background="{DynamicResource ModernPopupBrush}"/>

        <!-- Main TextBox -->
        <FacebookClient:CommandTextBox x:Name="PART_ShareTextBox" 
                                       FontSize="{DynamicResource MiddleFontSize}"
                                       Margin="6,6,6,0"
                                       Grid.Row="1" 
                                       SpellCheck.IsEnabled="True"
                                       AcceptsReturn="True"
                                       MinHeight="44"
                                       MaxHeight="88"
                                       FocusVisualStyle="{x:Null}"
                                       FontFamily="{DynamicResource SansSerifFont}"
                                       Style="{StaticResource SimpleCommandTextBox}" 
                                       BannerText="What's on your mind?" 
                                       CommitCommand="{x:Static FacebookClient:UpdateStatusControlModern.UpdateStatusCommand}" 
                                       Padding="3,3,20,3"
                                       TextWrapping="Wrap" />

        <!-- Main Cancel Button -->
        <ToggleButton Style="{DynamicResource OpacityButton}" Margin="0,8,8,0" IsChecked="{Binding Path=IsActive, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" VerticalAlignment="Top" HorizontalAlignment="Right" Grid.Row="1">
          <Path Data="{DynamicResource CancelGeometry}" Width="14" Height="14" Stretch="Uniform" Fill="#808080" />
        </ToggleButton>

        <!-- Link TextBox -->
        <FacebookClient:CommandTextBox x:Name="PART_LinkTextBox" Visibility="Collapsed" Grid.Row="2" Margin="6,6,6,0" Style="{DynamicResource SimpleCommandTextBox}" CommitCommand="{x:Static FacebookClient:UpdateStatusControlModern.UpdateStatusCommand}" SpellCheck.IsEnabled="False" Tag="Type or paste the link here..." />

        <!-- Image Area -->
        <Image Grid.Row="2" Margin="6,6,6,0" x:Name="PART_PhotoImage" MaxHeight="100" HorizontalAlignment="Left" Visibility="Collapsed" />

        <Button x:Name="ShareButton" Height="23" Grid.Row="3" Style="{StaticResource SmallIconButton}" Margin="0,6,12,6" Padding="0" Content="Share" Tag="{DynamicResource CheckGeometry}" MinHeight="0" HorizontalAlignment="Right" Command="{x:Static FacebookClient:UpdateStatusControlModern.UpdateStatusCommand}"
                IsEnabled="{Binding ElementName=PART_ShareTextBox, Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}" />
        <StackPanel Height="23" Margin="8,6,6,6" Grid.Row="3" Orientation="Horizontal" SnapsToDevicePixels="True">
          <Button x:Name="PhotoButton" Style="{StaticResource SmallIconButton}" Margin="0,0,12,0" Padding="0" Content="Attach a Photo" Tag="{DynamicResource PicturesGeometry}" MinHeight="0" Click="OnPhotoButtonClick" />
          <Button x:Name="LinkButton" Style="{StaticResource SmallIconButton}" Margin="0" Padding="0,0,-1,0" Content="Attach a Link" Tag="{DynamicResource LinksGeometry}" MinHeight="0" Click="OnLinkButtonClick" />
        </StackPanel>

      </Grid>

      <ControlTemplate.Triggers>
        <Trigger Property="DisplayMode" Value="Link">
          <Setter TargetName="PART_LinkTextBox" Property="Visibility" Value="Visible" />
          <Setter TargetName="LinkButton" Property="Content" Value="Remove Link" />
          <Setter TargetName="PhotoButton" Property="Visibility" Value="Collapsed" />
        </Trigger>
        <Trigger Property="DisplayMode" Value="Photo">
          <Setter TargetName="PART_PhotoImage" Property="Visibility" Value="Visible" />
          <Setter TargetName="LinkButton" Property="Visibility" Value="Collapsed" />
          <Setter TargetName="PhotoButton" Property="Content" Value="Remove Photo" />
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </UserControl.Template>

</UserControl>
